import random, struct

class SecureRandom(random.Random):
    def __init__(self, paranoid=False):
        self._file = None
        self._paranoid = paranoid
        self.seed()

    def seed(self):
        if self._file:
            try:
                close(self._file)
            except:
                pass
        if self._paranoid:
            fname = '/dev/random'
        else:
            fname = '/dev/urandom'
        self._file = open(fname, 'r')

    def rand(self):
        return abs(struct.unpack('l', self._file.read(4))[0])/(0.+((1<<31)))

    def randint(self):
        return struct.unpack('l', self._file.read(4))[0]

_SecRandom = SecureRandom()

def rand():
    global _SecRandom
    return _SecRandom.rand()

def randint():
    global _SecRandom
    return _SecRandom.randint()

def main():
    print rand()
    print randint()

if __name__ == '__main__':
    main()
